
import json
import requests

import queue
import threading
import time


print(time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime()))
# link = "https://static-data.eol.cn/www/2.0/school/30/info.json"
front_links = ["https://static-data.eol.cn/www/2.0/school/{}/info.json".format(i) for i in range(30, 623)]
end_links=["https://static-data.eol.cn/www/2.0/school/{}/info.json".format(i) for i in range(624,3700)]
all_links=front_links+end_links
# print(type(all_links))
# links.append(link)
with open("b.txt", "a+") as f:
    f.write("province_name name school_id num_master num_doctor num_subject num_lab"+"\n")
    print("loading..............")
    for i in all_links:
        data = requests.get(i)
        body=json.loads(data.text)

        if isinstance(body,dict):
        #学校名称
            name=body["data"]["name"]
        # 学校id
            school_id=body["data"]["school_id"]
        #省份
            province_name=body["data"]["province_name"]
        # 硕士点个数
            num_master=body["data"]["num_master"]
        # 博士点个数
            num_doctor=body["data"]["num_doctor"]
        # 国家特色学科个数
            num_subject=body["data"]["num_subject"]
        # 实验室个数
            num_lab=body["data"]["num_lab"]
        # 写入文件
            f.write(province_name+" "+name+" "+school_id+" "+num_master+" "+num_doctor+" "+num_subject+" "+num_lab+"\n")

print(time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime()))